package com.flowable.modules.modeler.configurations;

import com.flowable.modules.modeler.behavior.ExtActivityBehaviorFactory;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ActivitiConfig{


    @Value("${spring.datasource.url}")
    private String jdbcUrl;

    @Value("${spring.datasource.username}")
    private String jdbcUsername;

    @Value("${spring.datasource.password}")
    private String jdbcPassword;

    @Value("${spring.datasource.driver-class-name}")
    private String jdbcDriver;

    @Bean
    public ProcessEngine processEngine() {
        StandaloneProcessEngineConfiguration processEngineConfiguration = new StandaloneProcessEngineConfiguration();
        processEngineConfiguration.setJdbcUrl(jdbcUrl);
        processEngineConfiguration.setJdbcUsername(jdbcUsername);
        processEngineConfiguration.setJdbcPassword(jdbcPassword);
        processEngineConfiguration.setJdbcDriver(jdbcDriver);

        processEngineConfiguration.setActivityBehaviorFactory(new ExtActivityBehaviorFactory());
        processEngineConfiguration.setDatabaseSchemaUpdate("true");
        return processEngineConfiguration.buildProcessEngine();
    }
}
